<?php
//    require_once('class.BasicAnalyzer.php');
    /**
    * 用于提取6.cn网站的视频
    *
    */
    class SixroomsAnalyzer extends BasicAnalyzer implements Analyzer
    {
        public $features = array("url" => "/(6.cn\/watch\/.+|6.cn\/plist.*)/i");

        public function analyze($content, $url)
        {
            SOLOR_LOG("I am in analyze of 6.cn");
            SOLOR_LOG("URL : $url");
            $rv = array();
            preg_match( "/player.swf\?[^>]*vid=([^\"&]+)/i", $content, $rs);
            if (empty($rs)) return array();
            $vid = $rs[1];
            $xmlUrl = "http://6.cn/v72.php?vid=$vid&r=0";
            SOLOR_LOG("XMLURL: $xmlUrl");

            $body = $this->getPage($xmlUrl);

            SOLOR_LOG("XML_BODY: $body");
            preg_match( "/<file>(.+)<\/file>/", $body, $rs);
            if (empty($rs)) return array();
            //===================================
            $vurl = $rs[1];
            preg_match( "/<title>(.+)<\/title>/", $body, $rs);
            $title = $rs[1];
            preg_match( "/<li>标签: (.+)$/m", $content, $rs);
            $tmp = & $rs[1] || '';
            SOLOR_LOG($tmp);
            $tmp = preg_replace("/<[^>]+>/", "", $tmp);
            $tmp = preg_replace("/&nbsp;/", " ", $tmp);
            $tag = @ trim($tmp);
            $tag = explode(" ", $tag);
            $tag[] = "sr_6cn";
            preg_match( "/<li class=\"memo\">([^<]+)<\/li>/s", $content, $rs);
            $descr = @ trim($rs[1]);
            $referer = $url;

            preg_match( "/<li>频道: <a.*?>(.*?)<\/a>(.+)$/m", $content, $rs);
            $category = @ trim( & $rs[1]);
            $ext = "";
            preg_match( "/(上传于|更新于)([^<]+)<\/li>/", $content, $rs);
            $pub_date = @ trim( & $rs[2]);
            preg_match( "/<li><a href=\"\/profile\/[^>]+>([^<]+)</", $content, $rs);
            $author = @ trim($rs[1]);
            //===================================
            $rv = array(
                array(
                    "url" => $vurl, 
                    "title" => $title,
                    "descr" => $descr,
                    "referer" => $referer,
                    "tags" => $tag, 
                    "category" => $category,
                    "ext" => $ext,
                    "pub_date" => $pub_date,
                    "author" => $author
                    )
                );

            
            //===================================

            //$rv = array ($rs[1]); 
            return $rv;
        }
    }

?>
